<?php

namespace App\Model;

use App\Model\BaseModel;

class Post extends BaseModel
{
    protected $table = "posts";
    protected $fillable = ['title','content'];

    //关联用户
    public function user(){
    	return $this->belongsTo('\App\Model\User','user_id','id');
    }

    public function comments(){
    	return $this->hasMany('\App\Model\Comment')->orderBy('created_at','desc');
    }

    public function like($user_id){
    	return $this->hasOne(\App\Model\Like::class)->where('user_id',$user_id);
    }

    public function likes(){
    	return $this->hasMany('\App\Model\Like');
    }
}
